#include "qeventlabel.h"
#include <QMouseEvent>

QEventLabel::QEventLabel(QWidget *parent, Qt::WindowFlags f) :
    QLabel(parent, f),
    m_moving(false),
    m_checkMove(true),
    m_checkClick(false),
    m_message(0)
{
}

QEventLabel::~QEventLabel()
{
    //delete m_message;
}

void QEventLabel::setMessage(QString &msg)
{
    if (m_message)
        m_message->setPlainText(msg);
}


void QEventLabel::mouseReleaseEvent(QMouseEvent *ev)
{
    if(m_checkClick && ev->button() == Qt::LeftButton)
    {
        emit onClick();
    }
    if (m_checkMove)
        stopMoving();
}

void QEventLabel::mousePressEvent(QMouseEvent* pe)
{
    if (!m_checkMove)
        return;
    m_ptPosition = pe->pos();
    if (pe->y() < 31)
        startMoving();
}

void QEventLabel::mouseMoveEvent(QMouseEvent* pe)
{
    if (!m_checkMove)
        return;
    if (isMoving())
        move(pe->globalPos() - m_ptPosition);
}
